# -*- coding: utf-8 -*-

from core.resources import CustomerModelResource
from import_export.fields import Field
from import_export.widgets import ForeignKeyWidget
from apps.pms.models import Product, Version
from .models import TestPlan
from .widget import *


class TestPlanImportResouces(CustomerModelResource):
    product = Field(attribute="product", widget=ForeignKeyWidget(Product, field="name"))
    version = Field(
        attribute="version", widget=VersionForeignKeyWidget(Version, field="name")
    )

    class Meta:
        model = TestPlan
        fields = ("name", "product", "version", "run_time", "finished", "remark")
        import_id_fields = ("number",)
        export_order = fields


class TestPlanExportResouces(CustomerModelResource):
    product = Field(attribute="product", widget=ForeignKeyWidget(Product, field="name"))
    version = Field(attribute="version", widget=ForeignKeyWidget(Version, field="name"))

    class Meta:
        model = TestPlan
        fields = (
            "name",
            "product",
            "version",
            "scheduled_start",
            "scheduled_end",
            "remark",
        )
        export_order = fields
